﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace D7_Template
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            InitialCarList();
        }

        // 初始化 ListBox
        private void InitialCarList()
        {
            List<Car> carList = new List<Car>
            {
                new Car(){Automaker = "Lamborghini", Name = "Familys", Year="1990", TopSpeed = "340"},
                new Car(){Automaker = "Lamborghini", Name = "Models", Year="2001", TopSpeed = "353"},
                new Car(){Automaker = "Lamborghini", Name = "ModelHero", Year="2003", TopSpeed = "325"},
                new Car(){Automaker = "Lamborghini", Name = "Reventon", Year="2008", TopSpeed = "356"},
            };

            // 填充数据源
            this.listBoxCars.ItemsSource = carList;
        }
    }

    // 厂商名称转换成Logo图片路径
    public class AutomakerToLogoPathConverter : IValueConverter
    {
        // 正向转换
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string uriStr = $"/Resources/Logos/{(string)value}.png";
            return new BitmapImage(new Uri(uriStr, UriKind.Relative));
        }

        // 未被用到
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    // 汽车名称转换为照片路径
    public class NameToPhotoPathConverter : IValueConverter
    {
        // 正向转换
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string uriStr = $"/Resources/Images/{(string)value}.jpg";
            return new BitmapImage(new Uri(uriStr, UriKind.Relative));
        }

        // 未被用到
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
